package com.bensonbasement.snorflux.memory;

public class RSmallEntity extends REntity {

	private IRSmallEntityHolder location;
	private SmallEntityInfo info;
	
	public RSmallEntity(RWorld world, SmallEntityInfo info) {
		super(world);
		this.setInfo(info);
	}

	public void setInfo(SmallEntityInfo info) {
		IRSmallEntityHolder newLocation = (IRSmallEntityHolder) this.getWorld().getWorldElement(info.getLocationID());
		if (newLocation != this.location) {
			this.setLocation(newLocation);
		}
		this.info = info;
	}
	
	public void setLocation(IRSmallEntityHolder newLocation) {
		IRSmallEntityHolder oldLocation = this.location;
		if (newLocation != oldLocation) {
			if (oldLocation != null) {
				oldLocation.removeSmallEntity(this);
			}
			if (newLocation != null) {
				newLocation.addSmallEntity(this);
			}
			this.location = newLocation;
		}

	}

	@Override
	public IRSmallEntityHolder getLocation() {
		return location;
	}

	@Override
	public void leaveLocation() {
		this.setLocation(null);
	}

	@Override
	protected SmallEntityInfo getInfo() {
		return this.info;
	}
}
